package com.shop.service.impl;

import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import com.shop.entity.ShopProductTemplateEnum;
import com.shop.mapper.ShopProductTemplateEnumMapper;
import com.shop.service.ShopProductTemplateEnumService;
import org.springframework.stereotype.Service;

/**
 * 服务层实现。
 *
 * @author 彭新才
 * @since 2024-10-12
 */
@Service
public class ShopProductTemplateEnumServiceImpl extends ServiceImpl<ShopProductTemplateEnumMapper, ShopProductTemplateEnum> implements ShopProductTemplateEnumService {

    @Override
    public boolean add(ShopProductTemplateEnum shopProductTemplateEnum) {
        String code = shopProductTemplateEnum.getCode();
        String value = shopProductTemplateEnum.getValue();
        QueryWrapper query = new QueryWrapper()
                .eq(ShopProductTemplateEnum::getCode, code)
                .eq(ShopProductTemplateEnum::getValue, value);
        ShopProductTemplateEnum productTemplateEnum = getOne(query);
        if (productTemplateEnum != null) {
            throw new RuntimeException("模板已存在，请勿重复添加");
        }
        return save(shopProductTemplateEnum);
    }
}
